<?php echo $this->fetch('top.html'); ?>
<script type="text/javascript">
    var shippings = <?php echo $this->_var['shippings']; ?>;
    var addresses = <?php echo $this->_var['addresses']; ?>;
    var goods_amount = <?php echo $this->_var['goods_info']['amount']; ?>;
    var goods_quantity = <?php echo $this->_var['goods_info']['quantity']; ?>;;
$(function(){
    $('ul[shipping_id]').each(function() {
        var _shipping_fee = get_shipping_fee($(this).attr('shipping_id'));
        $(this).find('[ectype="shipping_fee"]').html(price_format(_shipping_fee));
    }).click(function() {
        set_order_amount($(this).attr('shipping_id'));
    });

    //select first
    set_order_amount($($('ul[shipping_id]')[0]).attr('shipping_id'));
});
function set_order_amount(shipping_id) {
    var _shipping_fee = get_shipping_fee(shipping_id);
    var _amount = goods_amount + _shipping_fee;
    $('#order_amount').html(price_format(_amount));
}
function get_shipping_fee(shipping_id) {
    var shipping_data = shippings[shipping_id];
    var first_price = Number(shipping_data['first_price']);
    var step_price = Number(shipping_data['step_price']);
    return first_price + (goods_quantity - 1) * step_price;
}
function check_phone() {
    return ($('#phone_tel').val() == '' && $('#phone_mob').val() == '');
}
function hide_error() {
    $('#region').find('.error').hide();
}
</script>
<div id="main"  data-role="page">
  
	<div class="bar-wrap <?php if ($_GET['app'] == 'member' && $_GET['act'] == ''): ?>w<?php endif; ?>">
		<div class="top-bar"> <a href="<?php if ($_GET['act'] == '' && $_GET['app'] != 'member'): ?><?php echo url('app=member'); ?><?php elseif ($_GET['app'] == 'member' && $_GET['act'] == ''): ?>mobile/index.php<?php else: ?>javascript:pageBack();<?php endif; ?>" class="pageback"><span></span></a>
			<h2 class="yahei">确认订单</h2>
			<a href="javascript:;" class="pagemore J_pagemore"><span></span></a>
	    </div>
		<div class="eject-tab J_eject_tab w-full clearfix hidden">
			 <a href="index.php"> <span></span>
			<p>首页</p>
			</a> <a href="<?php echo url('app=search'); ?>"> <span class="icon2"></span>
			<p>分类搜索</p>
			</a> <a href="<?php echo url('app=cart'); ?>"> <span class="icon3"></span>
			<p>购物车</p>
			</a> <a href="<?php echo url('app=member'); ?>"> <span class="icon4"></span>
			<p>用户中心</p>
			</a> 
		 </div>
	</div>
   
  <form method="post" id="order_form">
    <div class="page-order" id="page-order"> 
	<?php echo $this->fetch('order.shipping.html'); ?>
      <?php echo $this->fetch('order.goods.html'); ?>
      <?php echo $this->fetch('order.amount.html'); ?> </div>
  </form>
  <?php echo $this->fetch('footer.html'); ?> </div>
<div style="background:#F1F1F1" class="more-addr" data-role="page" id="more-addr"> 
  <?php $_from = $this->_var['my_address']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }; $this->push_vars('', 'address');$this->_foreach['address_select'] = array('total' => count($_from), 'iteration' => 0);
if ($this->_foreach['address_select']['total'] > 0):
    foreach ($_from AS $this->_var['address']):
        $this->_foreach['address_select']['iteration']++;
?>
  <div class="post-addr <?php if (($this->_foreach['address_select']['iteration'] <= 1)): ?>addr-selected<?php endif; ?>" addr_id="<?php echo $this->_var['address']['addr_id']; ?>">
    <article class="wrap mt10">
      <ul>
        <li class="consignee">
          <div class="content-inline-list">
            <div class="content-title">收货信息</div>
            <div class="content-detail"><?php echo htmlspecialchars($this->_var['address']['consignee']); ?> <?php if ($this->_var['address']['phone_mob']): ?><?php echo $this->_var['address']['phone_mob']; ?><?php else: ?><?php echo $this->_var['address']['phone_tel']; ?><?php endif; ?></div>
          </div>
        </li>
        <li class="address-content" >
          <div class="content-inline-list">
            <div class="content-title">收货地址：</div>
            <div class="content-detail"><span class="content-detail-addr"><?php echo htmlspecialchars($this->_var['address']['region_name']); ?>&nbsp;&nbsp;  <?php echo htmlspecialchars($this->_var['address']['address']); ?></span><a data-transition="slide" href="#more-addr">
              <aside class="content-nav">&nbsp;</aside>
              </a></div>
          </div>
        </li>
      </ul>
    </article>
  </div>
  <?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?> 
  <a href="<?php echo $this->_var['ret_url']; ?>" class="btn-white">添加新地址</a> </div>
	<div class="shipping-methods-list" id="shipping-methods-list" data-role="page"> 
	  <?php $_from = $this->_var['shipping_methods']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }; $this->push_vars('', 'shipping_method');$this->_foreach['shipping_select'] = array('total' => count($_from), 'iteration' => 0);
if ($this->_foreach['shipping_select']['total'] > 0):
    foreach ($_from AS $this->_var['shipping_method']):
        $this->_foreach['shipping_select']['iteration']++;
?>
	  <ul class="receive_add <?php if (($this->_foreach['shipping_select']['iteration'] <= 1)): ?>active<?php endif; ?>" shipping_id="<?php echo $this->_var['shipping_method']['shipping_id']; ?>">
		<li><?php echo htmlspecialchars($this->_var['shipping_method']['shipping_name']); ?>配送费用:&nbsp;<span class="money" ectype="shipping_fee">&yen; 0.00</span>
		  <aside class="content-nav">&nbsp;</aside>
		</li>
	  </ul>
	  <?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?> 
	</div>
	<a href="#main" data-transition="slide" id="J_back"></a> 
<script type="text/javascript">
		$("[name='address_options']").val($('#more-addr .post-addr').eq(0).attr('addr_id'));
		$('#more-addr .post-addr').click(function(){
			$('#J_back').trigger('click');
			$('.show-addr .J_addr'+$(this).attr('addr_id')).show().siblings().hide();
			$(this).addClass('addr-selected').siblings().removeClass('addr-selected');
			$("[name='address_options']").val($(this).attr('addr_id'));
		});
		$('.show-addr .address-content').click(function(){
			$('#J_other_addr').trigger('click');
		});
		
		$("[name='shipping_id']").val($('#shipping-methods-list .receive_add').eq(0).attr('shipping_id'));
		$('.order-goods-info .receive_add').click(function(){
			$('#J_shipping_list').trigger('click');
		});
		$('#shipping-methods-list .receive_add').click(function(){
			$('#J_back').trigger('click');
			$('.order-goods-info .J_shipping'+$(this).attr('shipping_id')).show().siblings().hide();
			$(this).addClass('active').siblings().removeClass('active');
			$("[name='shipping_id']").val($(this).attr('shipping_id'));
		});
</script> 